package com.qifan.energy.activity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.qifan.energy.R;
import com.qifan.energy.base.BaseActivity;
import com.qifan.energy.bean.result.MemberInfo;
import com.qifan.energy.global.Constant;
import com.qifan.energy.global.Keys;
import com.qifan.energy.util.ClipboardUtils;
import com.qifan.energy.util.SharedPreferencesUtil;
import com.qifan.energy.util.ToastUtils;
import com.qifan.energy.util.UMShareUtils;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MyShareCodeActivity extends BaseActivity {

    @BindView(R.id.qrcode_iv)
    ImageView qrcodeIv;
    @BindView(R.id.invitecode_tv)
    TextView invitecodeTv;
    private String copyCode = "";
    private Bitmap mBitmap;

    /*@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
    }*/

    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_sharecode;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        /* 更改状态栏 */
        changeStatusTransparentFontBlack();

        MemberInfo memberInfo = SharedPreferencesUtil.getData(Keys.USER_INFO_MEMBER_KEY,new MemberInfo());
        if (null != memberInfo) {
            invitecodeTv.setText(memberInfo.getInvitationCode());
            copyCode = memberInfo.getInvitationCode();
        }

        String textContent = "http://download.kaiyongzaixian.com/m1lp";
        mBitmap = CodeUtils.createImage(textContent, 400, 400, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
        qrcodeIv.setImageBitmap(mBitmap);
    }

    @Override
    protected void initData() {

    }

    @OnClick(R.id.copy_invitecode_tv)
    void onCopyInvitecodeClicked(){
        ClipboardUtils.copyText(copyCode);
        ToastUtils.showShort("已经复制");
    }

    @OnClick(R.id.confirm_tv)
    void onConfirmTvClicked(){
        /* 获取本地用户信息 */
        MemberInfo result = SharedPreferencesUtil.getData(Keys.USER_INFO_MEMBER_KEY,new MemberInfo());
        if (!TextUtils.isEmpty(result.getInvitationCode())){
            UMShareUtils.shareWxLink(this, "吼吼~，一大波机会正向您走来"
                    ,String.format("抓住它不再犹豫，快来加入我们吧，邀请码：%s",result.getInvitationCode())
                    ,String.format(Constant.SHARE_GIFT + "?invitationCode=%s",result.getInvitationCode())
                    ,R.mipmap.ic_launcher, null);
        }
    }
}
